package com.malie.myspringboot.designPattern.proxyPattern;

import java.util.Optional;

public class ProxyImage implements Image {

    private String fileName;
    private RealImage realImage;

    public ProxyImage(String fileName) {
        this.fileName = fileName;
    }

    @Override
    public void display() {
       /* if (realImage == null) {
            realImage = new RealImage(fileName);
        }*/
        realImage = Optional.ofNullable(this.realImage).orElseGet(() -> new RealImage(fileName));
        realImage.display();
    }

}
